// Definition of the Socket class

#ifndef Socket_class
#define Socket_class

#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <string>
#include <arpa/inet.h>


const int MAXHOSTNAME = 200;
const int MAXCONNECTIONS = 5;
const int MAXRECV = 500000;
//const int MSG_NOSIGNAL = 0; // defined by dgame

class Socket
{
 	public:
  		Socket();
  		virtual ~Socket();

  		// Server initialization
  		bool create();
  		bool bind ( const int port );
  		bool listen() const;
  		bool accept ( Socket& ) const;

		bool close();

  		// Client initialization
  		bool connect ( const std::string host, const int port );

  		// Data Transimission
  		bool send ( const std::string ) const;
		bool send ( void*, unsigned int );
	
		bool hasMsg ( void );
  		
		int recv ( std::string& ) const;
		int recv ( void*, unsigned int );

  		void set_non_blocking ( const bool );

  		bool is_valid() const { return m_sock != -1; }

		void PrintErrors();

 	private:

  		int m_sock;
  		sockaddr_in m_addr;
  		fd_set infds;


};


#endif
